<template>
	<view class="ljapp articleList">
		<view class="content">
			<view class="card">
				<view class="title-outer">
					<view class="title u-flex u-flex-between">
						<view class="u-flex-fill">医生文章</view>
						<!-- <view class="ricon u-flex">
							<view>更多</view>
							<u-icon name="arrow-right" color="#888888"></u-icon>
						</view> -->
					</view>
				</view>
				<view class="article-list">
					<view class="item u-flex" v-for="(item,index) in group.list" :key="index" @click="gotoDetails(item)">
						<view class="u-flex-fill">
							<view class="tit">{{item.title}}</view>
							<view class="sub-tit">{{item.doctor.name}} | {{item.doctor.practice_organization}}知名医生</view>
							<view class="u-flex u-flex-between">
								<view class="views">{{item.volume}}阅读</view>
								<view class="time">{{$u.timeFormat(item.createtime)}}</view>
							</view>
						</view>
						<image class="cover" :src="$base.cdn(item.img)" mode="aspectFill"></image>
					</view>
					<lj-empty paddingTop="80rpx" v-if="group.loaded&&group.list.length<=0">暂无文章</lj-empty>
					<view v-else>
						<u-loadmore
							:status="loading?'loading':(group.loaded?'nomore':'loadmore')"
							fontSize="28rpx"
							color="#d9d9d9"
							nomoreText="已加载全部"
							marginTop="30rpx"
							marginBottom="0"
							@loadmore="getList"
						></u-loadmore>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id: 0,
				group:{
					page: 1,
					limit: 10,
					list: [],
					loaded: false
				},
				loading: false,
			}
		},
		onLoad(options) {
			if(options.id) this.id = options.id
		},
		onShow(){
			this.init()
		},
		methods: {
			init(){
				this.group.page = 1
				this.group.list = []
				this.group.loaded = false
				this.loading = false
			
				this.getList();
			},
			getList(){
				var that = this,group = that.group;
				if(that.loading || group.loaded) return;
			
				that.loading = true
			
				this.$Http({
					url: 'doctorArticleList',
					data: {
						page: group.page,
						limit: group.limit,
						id: this.id,
					},
					type:'POST',
				}).then(res=>{
					if(res.code == 1){
						var list = res.data;
						group.loaded = list.length < group.limit;
						group.page ++;
						group.list = group.list.concat(list);
					}
					
					that.loading = false
				}).catch(()=>{
					that.loading = false
				});
			},
			onReachBottom(){
				this.getList()
			},
			gotoDetails(item){
				uni.navigateTo({
					url: '/pagesD/doctor/article?id='+item.id
				})
			}
		}
	}
</script>

<style lang="less">
	@import '@/pagesD/style.less';
	
</style>
